﻿package mortal.game.view.friendBless.view
{
    import Message.Game.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.scene3D.map3D.util.*;
    import mortal.game.view.friendBless.view.util.*;
    import mortal.game.view.friendBless.view.view.*;
    import mortal.mvc.core.*;

    public class FriendBlessController extends Controller
    {

        public function FriendBlessController()
        {
            return;
        }// end function

        override protected function initServer() : void
        {
            return;
        }// end function

        private function onGetCanBlessInfoHandler(param1:Object) : void
        {
            if (FriendBlessIcon.instance.isHide)
            {
                FriendBlessIcon.instance.show();
            }
            return;
        }// end function

        private function onShowBlessResultHandler(param1:Object) : void
        {
            var _loc_2:* = param1 as SCongratulateMsg;
            if (_loc_2)
            {
                if (_loc_2.fromPlayer.entityId.id == cache.role.entityInfo.entityId.id)
                {
                    switch(_loc_2.result)
                    {
                        case ECongratulateResult._ECongratulateSucess:
                        {
                            MsgManager.showMouseMsg("祝福成功", MsgRollTipsType.msgRollTips2);
                            break;
                        }
                        case ECongratulateResult._ECongratulateTimesUseUp:
                        {
                            MsgManager.showMouseMsg("对方被祝福次数已达上限", MsgRollTipsType.msgRollTips3);
                            break;
                        }
                        case ECongratulateResult._ECongratulateHadCongr:
                        {
                            MsgManager.showMouseMsg("该好友已经祝贺过了", MsgRollTipsType.msgRollTips3);
                            break;
                        }
                        default:
                        {
                            break;
                        }
                    }
                }
                if (_loc_2.toPlayer.entityId.id == cache.role.entityInfo.entityId.id && _loc_2.result == ECongratulateResult._ECongratulateSucess)
                {
                    cache.friendBless.addFriendBless(_loc_2.fromPlayer);
                    if (FriendCongratulationIcon.instance.isHide)
                    {
                        FriendCongratulationIcon.instance.show();
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.FriendBlessUpdateBlessList));
                }
            }
            return;
        }// end function

        private function onUpdateCongratuInfoHandler(param1:Object = null) : void
        {
            var _loc_2:* = cache.friendBless.sCongratulateInfo;
            if (_loc_2)
            {
                if (!FriendBlessBall.hasInstanceShowing() && cache.role.entityInfo.level >= GameConst.FriendOpenLevel && _loc_2.hadGain < FriendBlessConst.HasTakenReward_Zi && FriendBlessUtil.isInAvailableTime() && !GameMapUtil.isCopyMap())
                {
                    FriendBlessBall.instance.show();
                }
                if (FriendBlessBall.hasInstanceShowing() && _loc_2.hadGain > FriendBlessConst.HasTakenReward_Zi)
                {
                    FriendBlessBall.instance.hide();
                }
            }
            return;
        }// end function

        private function onShowOrHideBlessBall(event:DataEvent) : void
        {
            var _loc_2:* = event.data as Boolean;
            var _loc_3:* = cache.friendBless.sCongratulateInfo;
            if (FriendBlessBall.hasInstanceShowing() && !_loc_2)
            {
                FriendBlessBall.instance.hide();
            }
            else if (_loc_2 && cache.role.entityInfo.level >= GameConst.FriendOpenLevel && _loc_3 && _loc_3.hadGain < FriendBlessConst.HasTakenReward_Zi && FriendBlessUtil.isInAvailableTime())
            {
                FriendBlessBall.instance.show();
            }
            return;
        }// end function

        private function onLevelUpdateHandler(param1:Object) : void
        {
            if (!FriendBlessBall.hasInstanceShowing() && cache.role.entityInfo.level >= GameConst.FriendOpenLevel && FriendBlessUtil.isInAvailableTime() && !GameMapUtil.isCopyMap())
            {
                FriendBlessBall.instance.show();
            }
            return;
        }// end function

    }
}
